package logic

import (
	"context"
	"fmt"
	"rpc/model/mysql"

	"rpc/internal/svc"
	"rpc/turn"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsInfoLogic {
	return &GoodsInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsInfoLogic) GoodsInfo(in *turn.GoodsInfoRequest) (*turn.GoodsItem, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{}

	err := g.FindGoods(in.GoodsId)
	if err != nil {
		logx.Error("商品详情展示失败")
		return nil, fmt.Errorf("商品详情展示失败")
	}

	return &turn.GoodsItem{
		GoodsId:     int64(g.ID),
		GoodsName:   g.GoodsName,
		GoodsCover:  g.GoodsCover,
		GoodsPrice:  float32(g.GoodsPrice),
		GoodsStatus: int64(g.GoodsStatus),
		GoodsStock:  int64(g.GoodsStock),
		LikeCount:   int64(g.LikeCount),
	}, nil
}
